package Sort;

import java.util.Arrays;

public class Sort_01 {
    public static void main(String[] args) {
        int[] arr={121,34,145,2,3,9,7};
        Arrays.sort(arr);
        int i = Arrays.binarySearch(arr, 34);
        System.out.println(i);
        System.out.println(Arrays.toString(arr));
        System.out.println(binarysearch(arr,150));
    }


    public static int binarysearch(int[] arr,int number){
        int left=0;
        int right=arr.length-1;
        while(left<=right){
            int middleIndex=(right+left)/2;
            if (number<arr[middleIndex])
            {
                right=middleIndex-1;
            }else if (number>arr[middleIndex])
            {
                left=middleIndex+1;
            }
            else{
                return middleIndex;
                }

        }

        return -1;
    }
}
